import { useState } from 'react'
import { useNewPage } from '@hs-admin/utils'
import { HsAdminTablePage } from '@hs-admin/base-components'
import { postCompanyInfoDetailQueryLeadingMember } from '@/api/companyDetail/BasicInfor'
const MainMembers = (props: any) => {
  const { companyCode, hiddenModule } = props

  const [data, setdata] = useState([])

  const [total, setTotal] = useState(0)

  const columns: any[] = [
    {
      title: '序号',
      dataIndex: 'index',
      width: 80,
      render: (_: string, _record: any, index: number) => <>{index + 1 + (pagination.current - 1) * pagination.pageSize}</>
    },
    {
      title: '成员',
      dataIndex: 'personName'
    },
    {
      title: '职位',
      dataIndex: 'position'
    }
  ]
  /**
   * @description 获取表格数据
   */
  const getList = async () => {
    const res = await postCompanyInfoDetailQueryLeadingMember({
      current: pagination.current,
      pageSize: pagination.pageSize,
      companyCode: companyCode || '940bc2dc60b3adcddc804ca05ead707d'
    })
    setdata(res.data.list)

    setTotal(res.data.total)

    if (res.data.total) hiddenModule(res.data.total)

    return res.data
  }
  const { pagination } = useNewPage(getList)

  const MainMemberss = () => {
    return (
      <>
        {total ? (
          <div>
            <HsAdminTablePage
              scroll={{ x: 800, y: 650 }}
              columns={columns}
              dataSource={data}
              id="intellectual-property-patent"
              pagination={pagination}
              rowKey={(record: any) => `${record.personName}${record.position}`}
              size="small"
            />
          </div>
        ) : null}
      </>
    )
  }
  return (
    <div id="主要成员">
      <MainMemberss />
    </div>
  )
}
export default MainMembers
